#!/bin/bash
set -uo pipefail
#==============================================================#
# File      :   pg-cluster
# Desc      :   return pgsql cluster name
# Ctime     :   2020-12-17
# Mtime     :   2020-12-17
# Path      :   /pg/bin/pg-cluster
# Deps      :   psql
# License   :   AGPLv3 @ https://doc.pgsty.com/about/license
# Copyright :   2018-2025  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
PROG_NAME="$(basename $0)"
PROG_DIR="$(cd $(dirname $0) && pwd)"


#--------------------------------------------------------------#
#                             Usage                            #
#--------------------------------------------------------------#
# get pg_cluster from local conn or meta file
function pg_cluster() {
	local cluster_name=$(psql -AXtwqc "SHOW cluster_name;")
	if [[ ! -z "${cluster_name}" ]]; then
		echo ${cluster_name}
		return 0
	fi
	return 1
}


#--------------------------------------------------------------#
#                             Main                             #
#--------------------------------------------------------------#
pg_cluster